package com.lemon.springboot.controller;

import com.lemon.springboot.entity.AccountVo;
import com.lemon.springboot.entity.OverviewVo;
import com.lemon.springboot.service.IIndexPageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author liuli
 * @Date 2020/12/8 4:34
 *
 * 主机总览信息
 */
@Controller
public class IndexController {
    private static Logger logger = LoggerFactory.getLogger(IndexController.class);

    @Autowired
    IIndexPageService indexPageService;
    //首页
    @RequestMapping("/index")
    public String index(HttpServletRequest request, Model model) {
        try {
            AccountVo account = (AccountVo) request.getSession().getAttribute("account");
            List<OverviewVo> overviewData = indexPageService.getOverviewData(account.getAccount());
            if (overviewData != null && overviewData.size() > 0) {
                model.addAttribute("data", overviewData);
            }
            return "index";
        } catch (Exception e) {
            logger.error("index error.", e);
        }
        return "index";
    }
}
